package com.mdb.open.trade.feign.fallback;
/*
 * Copyright (C), 2017-2019 澳发科技(MDB)
 * FileName: OutreachFallbackFactory.java
 * Author:   符楚
 * Date:     2019-08-05 12:08
 * History:
 * <author>          <time>          <version>          <desc>
 * 符楚               2019-08-05          V1.00             新建
 * -----------------------------------------------------------
 * 作者姓名           修改时间           版本号            描述
 */

import com.mdb.bc.api.data.Result;
import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.api.enums.ResultCode;
import com.mdb.open.trade.feign.OutreachClient;
import com.mdb.open.trade.feign.dto.*;
import com.mdb.open.trade.feign.vo.CargoScanVo;
import com.mdb.open.trade.feign.vo.CoreLimitVo;
import com.mdb.open.trade.feign.vo.TradeFinanceBlacklistScanVo;
import com.mdb.open.trade.service.trade.handle.vo.DDAccVo;
import com.mdb.open.trade.service.trade.handle.vo.LoanAccountInfoVo;
import com.mdb.open.trade.service.trade.handle.vo.LoanCommitVo;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * <br>
 * <br>
 *
 * @author 符楚
 * @Date 2019-08-05 12:08
 */
@Slf4j
@Component
public class OutreachFallbackFactory implements FallbackFactory<OutreachClient> {
    @Override
    public OutreachClient create(Throwable throwable) {

        log.error("调用外联中心服务[cnt-outreach]发生异常", throwable);
        ResultEx result = ResultEx.makeResult(ResultCode.INVOKING_REMOTE_SERVICE, "调用外联中心服务服务发生异常");

        return new OutreachClient() {

            @Override
            public Result<String> companyVerify(CompanyVerifyDto dto) {
                result.setRetMsg("调用企业三要素验证失败");
                return result;
            }

            @Override
            public ResultEx<CoreLimitVo> requestCoreLimitApi0351070(CoreLimitDto dto) {
                result.setRetMsg("调用额度查询失败");
                return result;
            }
            @Override
            public ResultEx<DDAccVo> requestCoreApi0351108(CommonRequestDto dto) {
                result.setRetMsg("OutReachWebFallback error info: requestCoreApi0351108 error! Cause:{}" + throwable.getMessage());
                return ResultEx.fail();
            }
            @Override
            public ResultEx<LoanCommitVo> requestCoreApi0351321(CommonRequestDto dto) {
                result.setRetMsg("OutReachWebFallback error info: requestCoreApi0351321 error! Cause:{}" + throwable.getMessage());
                return ResultEx.fail();
            }
            @Override
            public ResultEx<LoanAccountInfoVo> requestCoreApi0131394(CommonRequestDto dto) {
                result.setRetMsg("OutReachWebFallback error info: requestCoreApi0131394 error! Cause:{}" + throwable.getMessage());
                return ResultEx.fail();
            }
            @Override
            public ResultEx<CargoScanVo> cargoScan(CargoScanDto dto) {
                result.setRetMsg("OutReachCrlaWebFallback error info: cargoScan error! Cause:{}" + throwable.getMessage());
                return ResultEx.fail();
            }
            @Override
            public ResultEx<TradeFinanceBlacklistScanVo> tradeFinanceBlacklistScan(TradeFinanceBlacklistScanDto dto) {
                result.setRetMsg("OutReachCrlaWebFallback error info: tradeFinanceBlacklistScan error! Cause:{}" + throwable.getMessage());
                return ResultEx.fail();
            }
        };
    }
}
